package org.dreamwork.jasmine2.web.client;

import java.util.regex.Matcher;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 12-4-26
 * Time: 下午8:18
 */
public class ChromeParser {
/*
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19
group[1]=535.19
group[2]=18.0.1025.162
group[3]=535.19

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13
group[1]=534.13
group[2]=9.0.597.98
group[3]=534.13

Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.12 (KHTML, like Gecko) Maxthon/3.3.6.2000 Chrome/18.0.966.0 Safari/535.12
group[1]=535.12
group[2]=18.0.966.0
group[3]=535.12

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.9 (KHTML, like Gecko) Chrome/20.0.1115.1 Safari/536.9
group[1]=536.9
group[2]=20.0.1115.1
group[3]=536.9

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16
group[1]=534.16
group[2]=10.0.648.204
group[3]=534.16
 */
    public static UserAgent parse (Matcher m) {
        UserAgent agent = new UserAgent (m.group (0));
        agent.setType (BrowserType.Chrome);
        OperationSystem os = OSParser.parseOS (m.group (0));
        agent.setOs (os);

        Version version = new Version (m.group (1));
        RenderKernel kernel = new RenderKernel (RenderkernelType.AppleWebKit, version);
        agent.setKernel (kernel);

        Architecture arch = os.getArchitecture ();
        agent.setDevice (DeviceTypeUtil.getDeviceType (arch));

        version = new Version (m.group (2));
        agent.setVersion (version);

        return agent;
    }
}
